package com.atguigu.spring.bean;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


@Data
@Component
public class Person implements ApplicationContextAware {

	//可以要到ioc容器
	ApplicationContext context;
	private String name;
	//@Autowired
	private Cat cat;

	public ApplicationContext getContext() {
		return context;
	}

	//去容器中找 会根据scop作用域 再创建一个实例
	@Lookup
	public Cat getCat() {
		return cat;
	}

	public void setCat(Cat cat) {
		this.cat = cat;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Person{" +
				"name='" + name + '\'' +
				'}';
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		//利用回调把ioc容器传入
		this.context = applicationContext;
	}
}
